import { AudioSource } from "cc";
import { Singleton } from "../Common";
import ResourcesManager from "./ResourcesManager";
import { AudioClip } from "cc";
import { createUINode } from "../Utils";

export enum Mp3TypeEnum {
    shoot = 'shoot'
}

export default class Mp3Manager extends Singleton {

    static get Ins() {
        return super.GetInstance<Mp3Manager>()
    }

    mp3Map: Map<string, AudioSource> = new Map()


    async play(type: Mp3TypeEnum) {

        const as = this.mp3Map.get(type)
        if (as) {
            as.play()
        } else {
            const ac = await ResourcesManager.Ins.loadRes('mp3/' + type, AudioClip)
            const node = createUINode(type)
            const as = node.addComponent(AudioSource)
            as.clip = ac
            this.mp3Map.set(type, as)
            as.play()
        }
    }

}